﻿
#pragma once
#include <onnxruntime_cxx_api.h>
#include <fstream>
#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <sstream>
#include <string>

using namespace Ort;

struct Net_config {
    float confThreshold;  // Confidence threshold
    float nmsThreshold;   // Non-maximum suppression threshold
    std::string modelpath;
};

typedef struct BoxInfo {
    float x1;
    float y1;
    float x2;
    float y2;
    float score;
    int label;
} BoxInfo;

class YOLOV7 {
   public:
    YOLOV7(Net_config config, std::string yoloname);
    std::vector<BoxInfo> detect(cv::Mat& frame);
    std::vector<std::string> class_names;

   private:
    int inpWidth;
    int inpHeight;
    int nout;
    int num_proposal;
    int num_class;

    float confThreshold;
    float nmsThreshold;
    std::vector<float> input_image_;
    void normalize_(cv::Mat img);
    void nms(std::vector<BoxInfo>& input_boxes);
    Env env = Env(ORT_LOGGING_LEVEL_ERROR, "YOLOV7");
    Ort::Session* ort_session = nullptr;
    SessionOptions sessionOptions = SessionOptions();

    std::vector<char*> input_names;
    std::vector<char*> output_names;
    std::vector<std::vector<int64_t>> input_node_dims;   // >=1 outputs
    std::vector<std::vector<int64_t>> output_node_dims;  // >=1 outputs

    //-------------------onnx更新后，ort_session->GetOutputName弃用，更新api后，需添加这两项vector------------
    std::vector<AllocatedStringPtr> In_AllocatedStringPtr;
    std::vector<AllocatedStringPtr> Out_AllocatedStringPtr;
};
